<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Articlecate_m extends FOX_Model
{

	function __construct ()
	{
		parent::__construct();
	}

	public function add_cate($data)
	{
		$this->db->insert('article_category',$data);
	}
	
	public function update_cate($id,$data)
	{
		$this->db->where('id',$id)->update('article_category', $data);
		return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
	}
	public function del_cate($id)
	{
		$this->db->where('id',$id)->delete('article_category');
		// $this->db->where('pid',$node_id)->delete('article_category');
		
	}
	public function get_cates_by_pid($pid)
	{
		$this->db->select('*');
		$query = $this->db->where('pid',$pid)->get('article_category');
		return $query->result_array();
	}
	public function get_article_category_by_id($id)
	{
		$this->db->where('id',$id);
		$query = $this->db->get('article_category');
		return $query->row_array();
	}
	public function get_all_cates()
	{
		$this->db->select('id,pid,article_category_name');
        $this->db->from('article_category');
		$this->db->order_by('id', 'desc');
        $query = $this->db->get();
        if($query->num_rows() > 0){
            return $query->result_array();
        }
	}
	public function get_cates_by_all_article_category($all_article_category,$pid=0){
		$this->db->select('*');
		$query = $this->db->where('all_article_category',$all_article_category)->where('pid',$pid)->get('article_category');
		return $query->result_array();
	}
    public function get_sub_cates_by_all_article_category($pid=0){
        $this->db->select('*');
        $query = $this->db->where('pid',$pid)->get('article_category');
        return $query->result_array();
    }

    public function get_sub_article_category(){
        $this->db->select('*');
        $query = $this->db->where('pid !=',0)->get('article_category');
        return $query->result_array();
    }
	
}